package com.itheima.tcp2;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.InetAddress;
import java.net.Socket;
import java.net.UnknownHostException;

/*
客户端 发送数据
并 接收 服务端的数据
 */
public class Client {

    public static void main(String[] args) throws IOException {
        Socket socket = new Socket(InetAddress.getByName("127.0.0.1"), 1314);

        //获取输出流
        OutputStream os = socket.getOutputStream();
        os.write("hello".getBytes());
       // os.close();
        //其他的办法   单独给一个结束标记
        socket.shutdownOutput();//禁用输出流
        InputStream is = socket.getInputStream();
        int b;
        while ((b=is.read())!=-1){
            System.out.print((char)b);
        }
        //is.close();
        socket.close();

    }
}
